var DEFAUL_EMPTY_SYMBOL = " - ";

var Triangule= function(){
};

/**
 * Create and draw the triangule
 * @param  {[number]} base   [base of the triangule]
 * @param  {[string]} symbol [symbol to draw]
 */
Triangule.prototype.createTriangule = function (base, symbol){
	var matrix = this.createMatrix(base);
	this.pullMatrixWithSymbols(matrix, symbol);
	this.draw(matrix);
};

/**
 * Create a matrix with predefined values
 * @param  {[type]} filas [description]
 * @return {[type]}       [description]
 */
Triangule.prototype.createMatrix = function (filas){
	var matrix = [];
	var columnas = filas + filas - 1;
	for (var i = 0; i < filas; i++) {
		matrix[i] = new Array(columnas);
	};
	this.initialize(matrix)
	return matrix;
};

/**
 * Pull the matrix with the symbols choosen
 * @param  {[array bidimensional]} matrix [needed to draw the triagule]
 * @param  {[string]} symbol [symbol to draw]
 */
Triangule.prototype.pullMatrixWithSymbols = function (matrix, symbol){
	var heigth = matrix.length;
	// needed due to stetic design with even number in base
	var width = heigth + heigth -1;
	var emptySpace = 0
 	var base = matrix.lenght;
 	var symbol1, symbol2;
	// iterate over the rows starting from the base
	for (var i = matrix.length - 1; i >= 0; i--) {
		// needed to draw different symbols according to the row
		symbol1 = this.isEven(emptySpace) ? symbol : DEFAUL_EMPTY_SYMBOL;
		symbol2 = this.isEven(emptySpace) ? DEFAUL_EMPTY_SYMBOL : symbol;
		// iterate over the columns, drawing the symbol or space
		for (var j = 0 + emptySpace; j < width - emptySpace; j++) {
			if (this.isEven(j)) {
				matrix[i][j] = symbol1;
			} else {
				matrix[i][j] = symbol2;
			};
		};
		//decrease the iteration so you can create the triangule
		emptySpace++;
	};
};

Triangule.prototype.draw = function (matrix){
	for (var i = 0; i < matrix.length; i++) {
		for (var j = 0; j < matrix[i].length; j++) {
			document.write(matrix[i][j]);
		};
		document.write("<br>");
	};
};

Triangule.prototype.initialize = function (matrix){
	for (var i = 0; i < matrix.length; i++) {
		for (var j = 0; j < matrix[i].length; j++) {
			matrix[i][j] = DEFAUL_EMPTY_SYMBOL;
		};
	};
};

Triangule.prototype.isEven = function (number){
	return number % 2 == 0;
};

//var myTriangule = new Triangule();
//myTriangule.createTriangule(10, "*");
//myTriangule.createTriangule(10, "*");
